#include <iostream>
#include<random>
#include<iomanip>
#include <arm_neon.h>
#include <stdio.h>
#include <time.h>
using namespace std;
const int N =1024;
float A[N][N];

void reset()
{
    A[0][0] = 0;
    for (int i = 0; i < N; i++)
    {
        A[i][i] = 1.0;
        for (int j = i + 1; j < N; j++)
        {
            A[i][j] = rand();//上三角赋值
        }
    }

    for (int k = 0; k < N; k++)
    {

        for (int i = k + 1; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                A[i][j] += A[k][j];//将上一行的数加到其下的每一行

            }
        }

    }
}

int main()
{
    reset();


    float32x4_t vt, va, vaik,vakj, vaij, vx;
    struct timespec sts,ets;
    timespec_get(&sts, TIME_UTC);

    for (int k = 0; k < N; k++)
    {
        vt = vdupq_n_f32(A[k][k]);
        int j = 0;
        for (j = k + 1; j+4 <=N; j+=4)
        {   float32_t *addr = &A[k][j];  // 内存地址
            va = vld1q_f32(addr);
            va = vdivq_f32(va, vt);// 这里是向量对位相除
            vst1q_f32(addr, va);// 将四个单精度浮点数从向量寄存器存储到内存
        }

        for (;j<N;j++)
        {
            A[k][j] = A[k][j] / A[k][k];// 该行结尾处有几个元素还未计算
        }
        

        A[k][k] = 1.0;

        for (int i = k + 1; i < N; i++)
        {
            vaik = vdupq_n_f32(A[i][k]);
            int j = 0;
            for (j = k + 1; j+4 <= N; j+=4)
            {
                 vakj = vld1q_f32(&A[k][j]);
                 vaij = vld1q_f32(&A[i][j]);
                 vx = vmulq_f32(vakj, vaik);
                 vaij = vsubq_f32(vaij, vx);
                 vst1q_f32(&A[i][j], vaij);
               
            }

            for (; j < N; j++)
            {
                A[i][j] = A[i][j] - A[i][k] * A[k][j];// 该行结尾处有几个元素还未计算
            }

            A[i][k] = 0;
        }

    }
    timespec_get(&ets, TIME_UTC);
    time_t dsec=ets.tv_sec-sts.tv_sec;
    long dnsec=ets.tv_nsec-sts.tv_nsec;
    if (dnsec<0){
    dsec--;
    dnsec+=1000000000ll;
    }
    printf ("%lld.%09llds\n",dsec,dnsec);
    
    return 0;
}
